package com.project.bohang.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.project.bohang.common.model.Response;
import com.project.bohang.common.model.page.PageResult;
import com.project.bohang.entity.House;
import com.project.bohang.entity.User;
import com.project.bohang.pojo.dto.HouseDto;
import com.project.bohang.pojo.vo.HouseVo;
import com.project.bohang.service.HouseService;
import com.project.bohang.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 *  用户管理
 *
 * @author bohang
 */
@Controller
@RequestMapping("/user")
@ResponseBody
public class UserController extends BaseController {

    @Autowired
    private UserService userService;

    @Autowired
    private HouseService houseService;

    /**
     * 登录
     *
     * @param user
     * @return
     */
    @PostMapping("/login")
    public Response<User> login(@RequestBody User user){
        return userService.login(user);
    }


    /**
     * 用户注册
     *
     * @param req
     * @return
     */
    @PostMapping("/register")
    public Response register(@RequestBody User req){
        return userService.register(req);
    }


    /**
     * 修改用户资料
     *
     * @param user
     * @return
     */
    @PostMapping("/updateUserInfo")
    public Response updateUserInfo(@RequestBody User user){
        return userService.updateUserInfo(user);
    }



    /**
     * 房屋列表 (不用token)
     *
     * @return
     */
    @PostMapping("/list")
    public Response<List<House>> selectList(){
        QueryWrapper<House> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("deleted",0);
        return Response.success(houseService.list(queryWrapper));
    }

}

